class_name InteractorComponent
extends BaseComponent

#region 属性
#endregion
#region 字段
var interactor:Interactor:
	get:
		return %Interactor
#endregion
#region 信号
#endregion

#region 基类方法
func init_component(args:Dictionary = {}):
	super(args)
	interactor.init(entity)
	var controller_component:ControllerComponent = entity.get_component(ControllerComponent)
	if controller_component:
		controller_component.register_key_action_state_changed_event(_on_controller_key_action_state_changed)
#endregion
#region 公共方法
func get_interactor() -> Interactor:
	return interactor
#endregion
#region 私有方法
func _on_controller_key_action_state_changed(key_action:GameEnum.KeyAction,key_action_state:GameEnum.KeyActionState):
	if key_action != GameEnum.KeyAction.Interact:
		return
	if key_action_state == GameEnum.KeyActionState.Idle:
		pass
	elif key_action_state == GameEnum.KeyActionState.Pressed:
		interactor.start_interact()
	elif key_action_state == GameEnum.KeyActionState.Released:
		interactor.end_interact()
	elif key_action_state == GameEnum.KeyActionState.Stay:
		interactor.interacting()
#endregion
#region 生命周期函数
#endregion
